﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO.WaiGaoQiao;
using System.Data;

namespace Model.WaiGaoQiao
{
    /// <summary>
    /// 物品信息
    /// </summary>
    public class Work_ArticleInfo
    {
        private DataAccessWork_Article workArticleAccess;

        public Work_ArticleInfo()
        {
            workArticleAccess = new DataAccessWork_Article();
        }
        /// <summary>
        /// 劳保数量
        /// </summary>
        /// <returns></returns>
        public int GetWork_ArticleCount(string Condition)
        {
            return workArticleAccess.GetWork_ArticleCount(Condition);
        }

        #region  ---------字段------------
        /// <summary>
        /// Id
        /// </summary>
        public int ID { get; set; }
        /// <summary>
        /// 物资编号
        /// </summary>
        public string ArticleNO { get; set; }
        /// <summary>
        /// 物质名称
        /// </summary>
        public string ArticleName { get; set; }
        /// <summary>
        /// 物资规格
        /// </summary>
        public string ArticleUnit { get; set; }
        /// <summary>
        /// 组织机构
        /// </summary>
        public int PriorId { get; set; }
        /// <summary>
        /// 领用类型
        /// </summary>
        public int GetType { get; set; }
        /// <summary>
        /// 物资颜色
        /// </summary>
        public string Color { get; set; }
        /// <summary>
        /// 规格ID
        /// </summary>
        public string ArticleUnitId { get; set; }
        #endregion
        /// <summary>
        /// 根据ID获取劳保物资名称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static string GetArticleNameByID(int id)
        {
            return DataAccessWork_Article.GetArticleNameByID(id);
        }
        /// <summary>
        ///根据id获取劳资物品对象
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public Work_ArticleInfo GetCon_ArticleById(int Id)
        {
            Work_ArticleInfo comInfo = new Work_ArticleInfo();
            DataSet ds = workArticleAccess.GetWork_ArticleById(Id);

            if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
            {
                DataRow item = ds.Tables[0].Rows[0];

                comInfo = new Work_ArticleInfo()
                {
                    ID = Convert.ToInt32(item[0]),
                    ArticleNO = item[1].ToString(),
                    ArticleName = item[2].ToString(),
                    ArticleUnit = item[3].ToString(),
                    PriorId = item[4].ToString() != "" ? Convert.ToInt32(item[4]) : 0,
                    GetType = Convert.ToInt32(item[5]),
                    Color =item[6].ToString()

                };
            }
            return comInfo;
        }
        /// <summary>
        /// 保存或修改劳保物资
        /// </summary>
        /// <param name="dmpara"></param>
        /// <returns></returns>
        public int SaveWork_Article(Work_ArticleInfo dminfo)
        {
            object[] dpmpara = new object[] {dminfo.ID, dminfo.ArticleNO,dminfo.ArticleName,dminfo.ArticleUnit,
                                              dminfo.PriorId,dminfo.GetType,dminfo.Color };
            return workArticleAccess.SaveWork_Article(dpmpara);
        }
        /// <summary>
        /// 根据条件获取所有劳资物品。
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<Work_ArticleInfo> GetAllCon_Article(string condition)
        {
            IList<Work_ArticleInfo> dmlist = new List<Work_ArticleInfo>();
            Work_ArticleInfo dminfo;
            DataSet ds = workArticleAccess.GetAllWork_Article(condition);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                dminfo = new Work_ArticleInfo();
                {
                    dminfo.ID = Convert.ToInt32(item[0]);
                    dminfo.ArticleNO = item[1].ToString();
                    dminfo.ArticleName = item[2].ToString();
                    dminfo.ArticleUnit = item[3].ToString();
                    dminfo.PriorId = item[4].Equals(DBNull.Value) ? 0 : Convert.ToInt32(item[4]);
                    dminfo.GetType = Convert.ToInt32(item[5]);
                    dminfo.Color = item[6].ToString();
                }
                dmlist.Add(dminfo);

            }
            return dmlist;
        }
        /// <summary>
        /// 获取所有劳资物品(分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<Work_ArticleInfo> GetAllCon_Article(string Condition, int pagesize, int startindex)
        {
            IList<Work_ArticleInfo> dmlist = new List<Work_ArticleInfo>();
            Work_ArticleInfo dminfo;
            DataSet ds = workArticleAccess.GetAllWork_Article(Condition, pagesize, startindex);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                dminfo = new Work_ArticleInfo();
                {
                    dminfo.ID = Convert.ToInt32(item[0]);
                    dminfo.ArticleNO = item[1].ToString();
                    dminfo.ArticleName = item[2].ToString();
                    dminfo.ArticleUnit = item[3].ToString();
                    dminfo.PriorId = item[4].Equals(DBNull.Value) ? 0 : Convert.ToInt32(item[4]);
                    dminfo.GetType = Convert.ToInt32(item[5]);
                    dminfo.Color = item[6].ToString();
                }
                dmlist.Add(dminfo);

            }
            return dmlist;
        }

        /// <summary>
        /// 是否存在子节点
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool IsExistSubNode(int id)
        {
            return workArticleAccess.IsExistSubNode(id);
        }
        /// <summary>
        /// 删除劳保物资
        /// </summary>
        /// <param name="did"></param>
        /// <returns></returns>
        public int DeleteWork_Article(string id)
        {
            return workArticleAccess.DeleteWork_Article(id);
        }
    }
}
